// pages/consultationRecord/index.js
import {
  ApiGetOrderListDrug,
  ApiPatientCardList,
  ApiOrderDrug,
  ApiPayTest
} from "../../api/index"
Page({



  /**
   * 页面的初始数据
   */
  data: {
    active: "all",
    name: '所有人',
    statusFormatter: [{
      label: '待支付',
      value: '1'
    }, {
      label: '已缴费',
      value: '2'
    }, {
      label: '已完成',
      value: '3'
    }, {
      label: '已取消',
      value: '4'
    }, {
      label: '已评价',
      value: '5'
    }, {
      label: '退款中',
      value: '6'
    }],
  },
  //进入问诊间
  /*  enterConsultationRoom(e) {
     console.log(e)
     let value = e.currentTarget.dataset.v
     let query = {
       consultation_order_id: value.id,
       doctor_id: value.doctor_id,
       doctor_name: value.doctor_name,
       department_name: value.department_name
     }
     wx.navigateTo({
       url: `/pages/messageDetail/index?contact=${JSON.stringify(query)}`,
     })
   }, */




  checkStatus(item) {
    this.data.statusFormatter.forEach(statusItem => {
      if (item.status == statusItem.value) {
        item.statusLabel = statusItem.label
      }
    })
  },
  // 切换就诊人
  exChangeClick() {
    this.setData({
      showpopup: true
    })
  },


  onClose() {
    this.setData({
      showpopup: false
    })
  },


  //缴费详情
  recordDetailClick(e) {
    wx.navigateTo({
      url: `/pages/drugRecordDetail/index?id=${e.currentTarget.dataset.v.id}`,
    })
  },




  submitConsultation(e) {
    wx.navigateTo({
      url: `/pages/drugPay/index?order=${JSON.stringify(e.currentTarget.dataset.v)}`
    })








    /*  this.setData({
       isLoading: true
     }) */
    /*   ApiOrderDrug(e.currentTarget.dataset.v.id).then(res => {
        if (res.code == '200') {
          wx.requestPayment({
            ...res.data,
            success(res) {
              that.getRecordList(e.currentTarget.dataset.v.patient_id)
            },
            fail(res) {
              that.getRecordList(e.currentTarget.dataset.patient_id)
            }


          })


        }
      }) */
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getRecordList()
    /*     this.getPatientList() */
  },
  //获取就诊人列表
  /*   getPatientList() {
      ApiPatientCardList().then(res => {
        this.setData({
          patientArr: res.data
        })
      })
    }, */
  getChangeData(e) {
    if (e.detail.value == 'all') {
      this.getRecordList()
    } else {
      this.getRecordList(e.detail.value)
    }
  },
  getRecordList(id) {
    this.setData({
      showpopup: false
    })
    wx.showLoading({
      title: '加载中'
    })
    ApiGetOrderListDrug({
      patient_id: id
    }).then(res => {
      if (res.code == 200) {
        res.data.forEach(item => {
          this.checkStatus(item)
        })
        this.setData({
          recordArr: res.data
        })
        wx.hideLoading()
      }
    })
  },


  //点击
  /*   selectPatient(e) {
      console.log(e)
      let value = e.currentTarget.dataset
      if (value.v == '所有人') {
        console.log('1')
        this.setData({
          active: 'all',
          name: '所有人',
        })
        this.getRecordList()
      } else {
        this.setData({
          active: value.info,
          name: value.v.name
        })
        this.getRecordList(value.v.id)
      }

    }, */
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})